from fastapi import FastAPI
from controllers.ocr_controller import router as ocr_router
from config import settings  # 可选：加载配置


from fastapi.middleware.cors import CORSMiddleware


app = FastAPI(title="OCR服务接口", version="1.0")

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

print(f"尝试加载.env文件: {settings.Config.env_file}")
print(f"配置值: {settings.model_dump()}")  # 打印所有配置值

# 注册路由
app.include_router(ocr_router)

@app.get("/config")
def get_config():
    return {
        "chat_api_key": settings.CHAT_API_KEY[:5] + "*****",  # 只显示前5个字符
        "retriever_api_key": settings.RETRIEVER_API_KEY[:5] + "*****",
        "base_url": settings.BASE_URL
    }

# 可选：配置日志、CORS等中间件
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)